<?php
/**
 *
 *
 */
class Ticket extends AppModel
{
    public $name       = "Ticket";
    public $primaryKey = "ticketId";


    public function get_stats()
    {
        $sql = "select (select count(*) from `tickets` where `status` = 'Open' and deleted = 0) as `open`,
                       (select count(*) from `tickets` where `status` = 'In Progress' and deleted = 0) as `in_progress`,
                       (select count(*) from `tickets` where `status` like 'Resolved%' and deleted = 0) as `resolved`
                from `tickets`
                group by `status`
                limit 1";

        return self::query($sql);
    }

    public function get_critical()
    {
        $sql = "select count(*) as `critical` from `tickets`
                where DATE_FORMAT(`date_added`, '%Y-%m-%d') < curdate() and
                      `status` = 'Open' and
                      deleted = 0";
        return self::query($sql);
    }

    public function get_ticket($marker = 'all', array $conditions, array $fields, $limit = null)
    {
        $limit = ($limit) ? $limit : null;
        return self::find($marker, array('conditions' => $conditions, 'fields' => $fields, 'limit' => $limit));
    }

}
?>